package com.mdd.admin.controller.session;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.session.IAdminSessionService;
import com.mdd.admin.validate.session.AdminSessionParam;
import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.vo.session.AdminSessionListVo;
import com.mdd.admin.vo.session.AdminSessionDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 会话管理
 */
@RestController
@RequestMapping("api/admin/session")
public class AdminSessionController {

    @Resource
    IAdminSessionService iAdminSessionService;

    /**
     * 会话列表
     *
     * @param pageParam 分页参数
     * @param params 搜索参数
     * @return Object
     */
    @GetMapping("/list")
    public Object list(@Validated PageParam pageParam,
                       @RequestParam Map<String, String> params) {
        PageResult<AdminSessionListVo> list = iAdminSessionService.list(pageParam, params);
        return AjaxResult.success(list);
    }
    /**
     * 会话详情
     *
     * @param id 主键ID
     * @return Object
     */
    @GetMapping("/detail")
    public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        AdminSessionDetailVo detail = iAdminSessionService.detail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 会话新增
     *
     * @param adminSessionParam 参数
     * @return Object
     */
    @Log(title = "会话新增")
    @PostMapping("/add")
    public Object add(@Validated(value = AdminSessionParam.create.class) @RequestBody AdminSessionParam adminSessionParam) {
        iAdminSessionService.add(adminSessionParam);
        return AjaxResult.success();
    }

    /**
     * 会话编辑
     *
     * @param adminSessionParam 参数
     * @return Object
     */
    @Log(title = "会话编辑")
    @PostMapping("/edit")
    public Object edit(@Validated(value = AdminSessionParam.update.class) @RequestBody AdminSessionParam adminSessionParam) {
        iAdminSessionService.edit(adminSessionParam);
        return AjaxResult.success();
    }

    /**
     * 会话删除
     *
     * @param adminSessionParam 参数
     * @return Object
     */
    @Log(title = "会话删除")
    @PostMapping("/del")
    public Object del(@Validated(value = AdminSessionParam.delete.class) @RequestBody AdminSessionParam adminSessionParam) {
       // iAdminSessionService.del(adminSessionParam.getId());
        return AjaxResult.success();
    }

}
